package j02pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class J1 {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(1);
        es.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+"= " + i);
                }
            }
        });
        es.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+" = " + i);
                }
            }
        });
        es.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+" = " + i);
                }
            }
        });
    }
}

class J2{
    public static void main(String[] args) {
        ExecutorService es = Executors.newCachedThreadPool();
//        ExecutorService es = Executors.newSingleThreadExecutor();
//        for (int i = 0; i < 3; i++) {
//            es.submit(new Runnable() {
//                @Override
//                public void run() {
//                    for (int i = 0; i < 100; i++) {
//                        System.out.println(Thread.currentThread().getName()+" = " + i);
//                    }
//                }
//            });
//        }
//        es.shutdown();
        es.submit(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000000; i++) {
                    System.out.println(Thread.currentThread().getName()+" = " + i);
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        es.shutdownNow();
        System.out.println("main end");

    }
}
